Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.1K
Vistas
WebSocket connection to "wss" sockjs-node failed for CRA and nginx reverse proxy

Here's my development setup:

  • I create a react project using create-react-app, inside docker
  • I serve it the usual way using npm start in my docker-compose.yml file
  • Now it's accessible on my localhost, using http://localhost:3000
  • To simulate server conditions, I seutp nginx and local DNS
  • In /etc/hosts I add 127.0.0.1 domain.local
  • Using mkcert I make locally valid certificates
  • In nginx I create the configuration file below:
server {
    listen 80;
    server_name domain.local;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    server_name domain.local;

    ssl_certificate /Temp/Project/Certificate.pem;
    ssl_certificate_key /Temp/Project/Key.pem;

    location / {
        proxy_pass http://localhost:3000;
    }
}

The problem is that when I go to https://domain.local instead of http://localhost:3000 I lose hot reloading, and I see this error in my console:

webpackHotDevClient.js:60 WebSocket connection to 'wss://domain.local/sockjs-node' failed:
../../Project/node_modules/react-dev-utils/webpackHotDevClient.js @ webpackHotDevClient.js:60
webpack_require @ bootstrap:851
fn @ bootstrap:150
1 @ index.js:7
webpack_require @ bootstrap:851
checkDeferredModules @ bootstrap:45
webpackJsonpCallback @ bootstrap:32
(anonymous) @ main.chunk.js:1
webpackHotDevClient.js:76 The development server has disconnected.
Refresh the page if necessary.

How can I solve this?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I am using proxy as well. So the question is how to setup your websocket connection in NGinx.

... hop-by-hop headers including “Upgrade” and “Connection” are not passed from a client to proxied server, therefore in order for the proxied server to know about the client’s intention to switch a protocol to WebSocket, these headers have to be passed explicitly:

location /sockjs-node {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

What they recommend doing is a bit longer.

I place localhost:3000 in previous example for you, but I prefer to use separate upstream directive so as not to mix upstreams and addresses. So the full example (inside http directive) would be:

upstream front {
    server localhost:3000;
}

map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}

server {
    listen 80;
    server_name domain.local;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    server_name domain.local;

    ssl_certificate /Temp/Project/Certificate.pem;
    ssl_certificate_key /Temp/Project/Key.pem;

    location / {
        proxy_pass http://front;
    }

    location /sockjs-node {
        proxy_pass http://front;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header Host $host;
    }
}

Haven't checked your example with cert`s, though.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda